<template>
<div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
        <el-form-item label="用户账号" prop="username" >
            <el-input
              v-model="queryParams.username"
              placeholder="请输入用户账号"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
            <el-button style="margin-left:15px" type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>
        <el-table v-loading="loading" :data="userList">
          <el-table-column label="用户账号" prop="userName" width="150px" align="center" />
          <el-table-column label="用户名称" prop="nickName" width="150px" align="center" />
          <el-table-column label="用户联系方式" prop="phonenumber" width="150px" align="center"/>
          <el-table-column label="认证信息"  prop="authInfo" width="150px" align="center"/>
          <el-table-column label="认证详情"  prop="authDetail" width="535px" align="center" :show-overflow-tooltip="true" />
          <el-table-column
            label="操作"
            align="center"
            width="160px"
            class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleUpdate(scope.row)"
              >通过审核</el-button>
              <el-button
                size="mini"
                type="text"
                @click="handleFreeze(scope.row)"
              >冻结账户</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
</div>
</template>

<script>
import { authListUser, changeUserStatus, infoAuth, passAuth } from "@/api/system/user";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import user from '../../../store/modules/user'

export default {
  name:"Userauth",
  inject:['reload'],//注入刷新当前页面的依赖
    data() {
        return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 表单参数
      form: {},

      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: undefined,
      },
        };
    },
  created() {
    this.getList();
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods:{
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      authListUser(this.addDateRange(this.queryParams)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
        userName: undefined,
        nickName: undefined,
        phonenumber: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 冻结用户
    handleFreeze(row) {
      let text ="停用";
      this.$confirm('确认要"' + text + '""' + row.userName + '"用户吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return changeUserStatus(row.userId, 1);
        }).then(() => {
          this.msgSuccess(text + "成功");
          this.reload();
        });
    },

    handleUpdate(row){
      let userInfo = {};
      userInfo.userName = row.userName;
      userInfo.userId = row.userId;
      userInfo.isAuth = '2';
      userInfo.authInfo = row.authInfo;
      userInfo.authDetail = row.authDetail;
      this.$confirm('确认通过用户'+row.userName+'的审核吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
         return passAuth(userInfo);
      }).then(() => {
        this.msgSuccess( "审核成功");
        this.reload();
      });
    }

  }

}
</script>
